<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--合同数据-->
      <el-col :span="20"
              :xs="24">
        <el-form :model="queryParams"
                 ref="queryForm"
                 size="small"
                 :inline="true"
                 v-show="showSearch"
                 label-width="68px">

          <el-form-item label="合同编号"
                        prop="contractNo">
            <el-input v-model="queryParams.contractNo"
                      placeholder="请输入合同编号"
                      clearable
                      style="width: 240px"
                      @keyup.enter.native="handleQuery" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary"
                       icon="el-icon-search"
                       size="mini"
                       @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh"
                       size="mini"
                       @click="resetQuery">重置</el-button>
          </el-form-item>

          <el-form-item>
            <el-col :span="1.5">
              <el-button type="primary"
                         plain
                         icon="el-icon-plus"
                         size="mini"
                         @click="handleCase">批量立案</el-button>
            </el-col>
          </el-form-item>

        </el-form>

        <el-table :data="contractList"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection"
                           width="50"
                           align="center" />
          <el-table-column label="合同编号"
                           align="center"
                           prop="contractNo"
                           v-if="columns[0].visible">
            <template slot-scope="scope">
              <el-button size="mini"
                         type="text"
                         icon="el-icon-view"
                         @click="handleDetails(scope.row)">{{scope.row.contractNo}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="专利名称"
                           align="center"
                           prop="patendName"
                           v-if="columns[1].visible"
                           :show-overflow-tooltip="true" />
          <el-table-column label="专利类型"
                           align="center"
                           prop="patendTypeId"
                           v-if="columns[2].visible"
                           :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ipms_patend_type" :value="scope.row.patendTypeId"/>
            </template>
          </el-table-column>
          <el-table-column label="客户联系人"
                           align="center"
                           prop="customerContact"
                           v-if="columns[3].visible"
                           :show-overflow-tooltip="true" />

              <el-table-column
                label="签约主体"
                align="center"
                width="160"
                class-name="small-padding fixed-width">
                <span>J8Studio.meta</span>
              </el-table-column>
          <el-table-column label="创建时间"
                           align="center"
                           prop="createTime"
                           v-if="columns[4].visible"
                           width="200px" />

          <el-table-column label="操作"
                           align="center"
                           width="160"
                           class-name="small-padding fixed-width">

            <template slot-scope="scope">
              <el-button size="mini"
                         type="text"
                         icon="el-icon-notebook-2"
                         @click="handleCase(scope.row)">立案</el-button>
            </template>

          </el-table-column>

        </el-table>
        <pagination v-show="total > 0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
//引入题目列表方法
import { listContract, updateContract } from '@/api/patent/zhc'
import { addCase } from '@/api/patent/Bao'
import { getContract } from '@/api/contract/lu'

export default {
  //声明使用字典
  dicts: [
    //专利类型字典
    'ipms_patend_type',
  ],
  data() {
    return {
      // 选中数组
      Nos: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 合同表格数据
      contractList: [],
      // 显示搜索条件
      showSearch: true,
      // 表单参数
      // form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNo: undefined,
      },
      // 列信息
      columns: [
        { key: 0, visible: true },
        { key: 1, visible: true },
        { key: 2, visible: true },
        { key: 3, visible: true },
        { key: 4, visible: true },
      ],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.Nos = selection.map((item) => item.contractNo)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    getList() {
      listContract(this.queryParams).then((response) => {
        this.contractList = response.rows
        this.total = response.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.contractNo = null
      this.handleQuery()
    },
    /** 立案操作 */
    handleCase(row) {
      const contractNos = row.contractNo || this.Nos
      //新增案件
      addCase(contractNos).then((res) => {
        //修改合同状态
        updateContract(contractNos).then((response) => {
          this.$message.success('立案成功')
          this.handleQuery()
        })
      })
    },
    /*查看合同详情*/
    handleDetails(row) {
      getContract(row.contractId).then((resp) => {
        this.$store.commit('SET_CONTRACT_OBJ', resp.data)
        //跳转合同详情
        this.$router.push({
          path: '/contract/details',
        })
      })
    },
  },
}
</script>

<style lang="stylus" scoped></style>
